const express = require("express");
const pool = require("../pool");
const router = express.Router();

// 价格查询
router.post("/query_price", (req, res, next) => {
  pool.query("select * from setprice", (err, result) => {
    if (err) return next(err);
    res.send({
      code: 200,
      msg: "success",
      data: result,
    });
  });
});

// 价格修改
router.post("/set_price", (req, res, next) => {
  let { price1, price2, price3, price4 } = req.body;
  pool.query(
    "update setprice set price1=?,price2=?,price3=?,price4=? where id = 1;",
    [price1, price2, price3, price4],
    (err, result) => {
      if (err) next(err);
      if (result.changeRows != 0) {
        res.send({
          code: 200,
          msg: "修改成功",
        });
      } else {
        res.send({
          code: 401,
          msg: "修改失败",
        });
      }
    }
  );
});

module.exports = router;
